<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="styles/style.css">
        <link rel="stylesheet" href="styles/theme/atom-one-dark.css">
        <title>例子22-JS进阶（三）</title>
    </head>
    <body>
        <pre>
            <code>
                    // 例子22

                    var text = 'javascript is fun';
                    text.replace(/javascript/gi, "Javascript"); // 'Javascript is fun', 将所有不区分大小写的javascript都替换成Javascript
                    text.replace(/\b\w+\b/g, function(word) { // 将字符串中的所有单词的首字母大写
                        return word.substring(0,1).toUpperCase() + word.substring(1); // 'Javascript Is Fun'
                    })
            </code>
        </pre>
        <script src="scripts/libs/highlight.pack.js"></script>
        <script src="scripts/22.js"></script>
        <script>
            hljs.initHighlightingOnLoad();
        </script>
    </body>
</html>